# encoding:utf-8

import time
OrderDate = time.strftime('%Y-%m-%d', time.localtime(time.time()))
OrderTime = time.strftime('%H:%M:%S', time.localtime(time.time()))

DrinkMenu = {1: "臭豆腐", 2: "腐乳", 3: "柠檬"}
FoodMenu = {1: "简简单单的米饭", 2: "扒鸭屁股是块宝", 3: "都说圆葱它很辣", 4: "老八秘制小汉堡"}
OrderList = []


def orderMenu():
    print("\n----欢迎点餐----")
    print("我们提供的配料有：")
    for drink in DrinkMenu:
        print(str(drink) + "：" + DrinkMenu[drink])
    drinkNO = int(input("请输入选择的配料序号（1--3）："))
    print(drinkNO)
    while drinkNO > 3:
        drinkNO = int(input("请重新输入（1--3）："))
    print("你选择了" + DrinkMenu[drinkNO] + "\n")
    print("我们提供的食品有：")
    for food in FoodMenu:
        print(str(food) + "：" + FoodMenu[food])
    foodNO = int(input("请输入选择的食品序号（1--4）："))
    print(foodNO)
    while foodNO > 4:
        foodNO = int(input("请重新输入（1--4）："))
    print("你选择了" + FoodMenu[foodNO] + "\n")
    totalPrice = getCharge(drinkNO, foodNO)
    print("不管是%s还是%s，到你嘴里你得盘他，%.2f元，既实惠，还管饱。" %
          (DrinkMenu[drinkNO], FoodMenu[foodNO], totalPrice))
    OrderList.append([
        OrderDate, OrderTime, DrinkMenu[drinkNO], FoodMenu[foodNO], totalPrice
    ])


def printMenu(OrderList):
    totalPrice = 0
    print("\n----统计报表----")
    print("点餐日期 \t 点餐时间 \t 配料 \t\t 食品 \t\t   花费（元）\n")
    for order in OrderList:
        totalPrice += order[4]
        print(order[0] + "\t" + order[1] + "\t%s\t\t%s\t\t%.2f元\n" %
              (order[2], order[3], order[4]))
    print("累计收入%.2f" % totalPrice)


def exportMenu(OrderList):
    dataFile = open("AllReport.txt", "w", -1, "utf-8")
    for order in OrderList:
        dataFile.write(order[0] + "," + order[1] + ",%s,%s,%.2f元\n" %
                       (order[2], order[3], order[4]))
    dataFile.close()
    print("---报表导出成功---")


def getCharge(drinkNO, foodNO):
    drinkCharge = 0.0
    foodCharge = 0.0
    if drinkNO == 1:
        drinkCharge += 3.0
    elif drinkNO == 2:
        drinkCharge += 4.5
    elif drinkNO == 3:
        drinkCharge += 4.0
    if foodNO == 1:
        foodCharge += 1.1
    elif foodNO == 2:
        foodCharge += 2.5
    elif foodNO == 3:
        foodCharge += 2.0
    elif foodNO == 4:
        foodCharge += 1.5
    return drinkCharge + foodCharge


while (True):
    print("\n------欢迎使用点餐系统------")
    print("本点餐系统提供如下功能：\n 1. 点餐\n 2. 打印报表功能\n 3. 存储报表\n 4. 退出系统")
    choice = int(input("请输入需要的一项功能："))
    if choice == 1:
        orderMenu()
    elif choice == 2:
        printMenu(OrderList)
    elif choice == 3:
        exportMenu(OrderList)
    elif choice == 4:
        exit(0)
    else:
        print("请输入正确的序号（1--4）。")
